package com.winhxd.b2c.common.util;

import org.apache.commons.codec.binary.Base64;

import java.io.UnsupportedEncodingException;

public class Base64Utils {

    public static String encode(String s) {
        try {
            return encode(s.getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static String encode(byte[] s) {
        if (s == null)
            return null;
        return Base64.encodeBase64URLSafeString(s);
    }

    public static byte[] decode(String s) {
        if (s == null)
            return null;
        return Base64.decodeBase64(s);
    }

}
